package dummy.randomsim

import mars.ns.Simulation
import mars.ns.TurnSimulation
import mars.ns.core._
import mars.ns.visualisation._
import mars.ns.stat.Statistics
import mars.io.formatters.StatsXMLFormatter
import mars.ns.selectors.ConnectSometimesRandomly
import mars.ns.statechangers.ConnectedStateChange

object TurnSim extends Application {
    var nodes : List[Node] = Nil
    for(i<- 0 until 100)
        nodes = new Node::nodes
    val net:Network[Node] = new Network[Node]()
    net.addNodes(nodes)
    val sim: TurnSimulation[Node] = new TurnSimulation(net, 10) with ConnectSometimesRandomly[Node] with ConnectedStateChange[Node]
    val stats: Statistics[Node] = new Statistics(1)
    sim.subscribe(stats)
	sim.subscribe(new VisualisationListener[Node](net))
	sim.run
	for((iteration, iterationData) <- stats.getGatheredData) {
	    println("---- iteration " + iteration + " ----")
	    for(dr<- iterationData) {
	        println("\t" + dr)
	    }
	}
    println("--- XML FORMATTER ---")
    var xml = (new StatsXMLFormatter).format(stats)
    println(xml)
    //println((new StatsXMLFormatter).validFormat(xml))
    println((new StatsXMLFormatter).fromString(xml).toString)
}